// 对应 RecipeModuleType == style1

import 'package:casdon/modules/recipe/domain/states/recipe_module_content_state.dart';
import 'package:casdon/modules/recipe/ui/widgets/recipe_card_style1.dart';
import 'package:casdon/auto_router.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

/// 通用的菜谱水平列表组件
class RecipeModuleStyle1Content extends StatelessWidget {
  final int maxCount;
  final RecipeModuleContentState state;

  const RecipeModuleStyle1Content({
    super.key,
    required this.maxCount,
    required this.state,
  });

  @override
  Widget build(BuildContext context) {
    if (state.data.isEmpty) {
      return const SizedBox.shrink();
    }
    return SizedBox(
      height: 128.h,
      child: ListView.builder(
        scrollDirection: Axis.horizontal,
        padding: EdgeInsets.symmetric(horizontal: 12.w),
        itemCount: state.data.length > maxCount ? maxCount : state.data.length,
        itemBuilder: (context, index) {
          final item = state.data[index];
          return InkWell(
            borderRadius: BorderRadius.circular(8),
            onTap: () {
              RecipeDetailRoute(
                recipeId: item.recipeId,
                title: item.title,
                isSmart: item.isSmart,
              ).push(context);
            },
            child: RecipeCardStyle1(item: item),
          );
        },
      ),
    );
  }
}
